package com.tianji.learning.controller;


import cn.hutool.log.Log;
import com.tianji.api.dto.course.CourseSimpleInfoDTO;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author chengge
 * @since 2024-06-20
 */
@RestController
@Slf4j
@RequestMapping("/lessons")
@RequiredArgsConstructor
@Api(tags = "我的课表")
public class LearningLessonController {
    private final ILearningLessonService learningLessonService;

    /**
     * 分页查询课程
     *
     * @param pageQuery
     * @return
     */
    @GetMapping("page")
    @ApiOperation("分页查询课程")
    public PageDTO<LearningLessonVO> addLesson(PageQuery pageQuery) {
        return learningLessonService.pagelesson(pageQuery);
    }

    /**
     * 查询当前学习的课程
     *
     * @return
     */
    @GetMapping("now")
    @ApiOperation("查询当前学习的课程")
    public LearningLessonVO queryNowLesson() {
        log.info("查询当前学习的课程");
        return learningLessonService.queryNowLesson();
    }

    /**
     * 查询课程状态
     *
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}")
    @ApiOperation("查询课程状态")
    public LearningLesson queryCourseStatus(@PathVariable("courseId") Long courseId) {
        return learningLessonService.queryCourseStatus(courseId);
    }

    /**
     * 删除课程
     *
     * @param courseId
     */
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除课程")
    public void deleteLesson(@PathVariable("courseId") Long courseId) {
        log.info("删除课程:{}", courseId);
        learningLessonService.deleteLesson(courseId);
    }

    /**
     * 校验指定课程是否是课表中的有效课程
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("校验指定课程是否是课表中的有效课程")
    public Long isLessonValid(@PathVariable("courseId") Long courseId) {
        return learningLessonService.isLessonValid(courseId);
    }

    /**
     * 统计课程学习人数
     * @param courseId 课程id
     * @return 学习人数
     */
    @GetMapping("{courseId}/count")
    @ApiOperation("统计课程学习人数")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return learningLessonService.countLearningLessonByCourse(courseId);
    }
}
